package com.yanqu.road.server.cmd.monopolymarket.fortress;

import com.yanqu.road.entity.monopolymarket.office.log.MonopolyMarketFortressDispatchLogData;
import com.yanqu.road.pb.monopolymarket.MonopolyMarketProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.monopolymarket.MonopolyMarketModule;
import com.yanqu.road.server.manger.MonopolyMarketCommonMgr;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.server.manger.monopolymarket.MonopolyMarketMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.date.DateHelper;

/**
 * @Description
 * @Author cwq
 * @Data 2021/10/15 16:32
 */
@Cmd(code = GameProtocol.S_MONOPOLY_MARKET_FORTRESS_DISPATCH_FROM_CROSS, desc = "边关要塞 派遣门客 跨服返回区服 协议")
public class MonopolyMarketFortressDispatchFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        MonopolyMarketProto.MonopolyMarketFortressUnionDispatchToGameServerMsg crossMsg = MonopolyMarketProto.MonopolyMarketFortressUnionDispatchToGameServerMsg.parseFrom(packet.getBytes());
        MonopolyMarketProto.MonopolyMarketFortressUnionDispatchRespMsg.Builder stcMsg = MonopolyMarketProto.MonopolyMarketFortressUnionDispatchRespMsg.newBuilder();
        stcMsg.setRet(crossMsg.getRet());
        if(crossMsg.getRet() == 0){
            // 同步玩家派遣信息
            MonopolyMarketModule monopolyMarketModule = player.getModule(MonopolyMarketModule.class);
            monopolyMarketModule.synFortressDispatchInfo(crossMsg.getFortressDispatchListList());
            monopolyMarketModule.synRoleData();

            LogMgr.addMonopolyMarketFortressDispatchLogData(new MonopolyMarketFortressDispatchLogData(MonopolyMarketMgr.group.getGroupId(),MonopolyMarketCommonMgr.getMonopolyMarketWeekId(),crossMsg.getFortressId(),player.getUserId(),crossMsg.getUnionId(),crossMsg.getPatronsStr(),crossMsg.getEarn(),crossMsg.getUnionEarn(), DateHelper.getCurrentSecond()));
        }
        player.sendPacket(ClientProtocol.U_MONOPOLY_MARKET_FORTRESS_DISPATCH, stcMsg);
    }

    @Override
    public void sendData(GamePlayer player) {
    }

}
